package com.learn.springcloud.feignparambindingconsumer.controller;

import com.learn.springcloud.feignparambindingconsumer.bean.User;
import com.learn.springcloud.feignparambindingconsumer.service.FeignTestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.jws.soap.SOAPBinding;
import java.util.*;

/**
 * @Time : 2018/8/8 19:46
 * @Version : 1.0
 */
@RestController
public class FeignParamBindingConsumer {

    @Autowired
    private FeignTestClient feignTestClient;

    @RequestMapping(value = "/feign/quick/start/consumer/say/hello/{name}", method = RequestMethod.GET)
    public String sayHello1(@PathVariable(name = "name") String name){
        return feignTestClient.hello(name);
    }

    @RequestMapping(value = "/feign/quick/start/consumer/say/hello1/", method = RequestMethod.POST)
    public String sayHello2(@RequestBody User user){
        return feignTestClient.hello(user.getName(), user.getAge()).toString();
    }

    @RequestMapping(value = "/feign/quick/start/consumer/say/hello2/", method = RequestMethod.POST)
    public String sayHello3(@RequestBody User user){
        return feignTestClient.hello(user);
    }

    @RequestMapping(value = "/feign/quick/start/consumer/say/hello4", method = RequestMethod.POST)
    public User sayHello4(@RequestBody User user){
        System.out.println(user);
        return feignTestClient.hello4(user);
    }

    @RequestMapping(value = "/feign/quick/start/consumer/say/hello5", method = RequestMethod.POST)
    public List<String> sayHello5(@RequestBody List<String> names){
        System.out.println(names);
        return feignTestClient.hello5(names);
    }

    @RequestMapping(value = "/feign/quick/start/consumer/say/hello6", method = RequestMethod.POST)
    public List<User> sayHello6(@RequestBody List<User> users){
        System.out.println(users);
        return feignTestClient.hello6(users);
    }

    /**
     * Postman 报文格式（users随意起名）
     {
         "users": [
             {
             "name": "aaa",
             "age": 10
             },
             {
             "name": "bbb",
             "age": 11
             },
             {
             "name": "ccc",
             "age": 12
             }
        ]
     }
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/feign/quick/start/consumer/say/hello7", method = RequestMethod.POST)
    public Map<String,List<User>> sayHello7(@RequestBody Map<String,List<User>> map){
        System.out.println(map);
        return feignTestClient.sayHello7(map);
    }

}
